Skip to content

Reduce runtime#21

Open
AuroraJohansen wants to merge 14 commits into
dbouget:masterfrom
AuroraJohansen:reduce_runtime
Open

Reduce runtime#21
AuroraJohansen wants to merge 14 commits into
dbouget:masterfrom
AuroraJohansen:reduce_runtime

Conversation

@AuroraJohansen

@AuroraJohansen AuroraJohansen commented Jun 25, 2026

Copy link
Copy Markdown

Changes

Refactor kfold_model_validation to use SQLite as primary data store

Previously, all metrics were stored in pandas DataFrames and written to CSV after each patient, causing O(n²) slowdown for large cohorts (e.g. patient 2400 took significantly longer than patient 1).

Key changes:

  • Introduced SQLite database (results.db) as the primary data store, with WAL mode enabled for crash-safe writes
  • Replaced per-patient CSV writes with SQLite INSERT/UPDATE operations
  • CSV files are now exported once after all folds are complete, rather than after each patient
  • Added resume support: existing database is reused on restart, with missing CSV files regenerated from the database if needed
  • Replaced init_from_file (which re-read the full CSV on every patient) with init_from_db, which queries only the relevant rows from SQLite, eliminating the O(n²) bottleneck
  • Extra metric columns are added via ALTER TABLE when new metrics are introduced after the initial run
  • compute_fold_average now reads all extra metric columns present in the CSV, not just those in the current config, preserving metrics from previous runs

Fix early-exit logic in compute_patient_extra_metrics to correctly skip already-computed metrics

The original early-exit check had two bugs:

  • Used x == x to detect computed values, which evaluates to True for None (since None == None is True in Python), causing the function to return early with None values instead of recomputing them.
  • Called get_optimal_class_extra_metrics multiple times redundantly.

The new implementation:

  • Checks explicitly that values are not None using v is not None and v == v
  • Only checks values relevant to the configured metric spaces (patientwise/objectwise) rather than assuming both are always present
  • Stores the result in a local variable to avoid repeated function calls

AuroraJohansen and others added 10 commits June 24, 2026 09:24
…igurable extra metrics

Previously, results_df_base_columns included current extra metrics (e.g. VOI),
causing them to be filtered out when building all_extra_metric_names and
missing from the fold average CSV files. Introduced results_df_fixed_columns
to represent only the non-configurable base columns, used for filtering.
…cation, fixing extra metrics computation [skip ci]
@dbouget
dbouget marked this pull request as ready for review July 3, 2026 09:29
@dbouget
dbouget self-requested a review July 3, 2026 09:30
@dbouget dbouget self-assigned this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants